import { request, type ApiResponse, type PaginationParams } from ".";

import { type Course } from "@/stores";

export type CreateCourseData = Pick<
  Course,
  "name" | "teacher" | "classroom" | "semester" | "term" | "nature"
>;
export type UpdateCourseData = CreateCourseData;
/**
 * 创建新课程
 * @param data 课程数据
 * @returns API响应，包含新创建的课程信息
 */
export function createCourse(data: CreateCourseData) {
  return request<ApiResponse<Course>>("/course", {
    method: "POST",
    body: JSON.stringify(data),
  });
}

/**
 * 更新现有课程
 * @param id 课程ID
 * @param data 课程数据
 * @returns API响应，包含更新后的课程信息
 */
export function updateCourse(id: number, data: UpdateCourseData) {
  return request<ApiResponse<Course>>(`/course/${id}`, {
    method: "PUT",
    body: JSON.stringify(data),
  });
}

export function deleteCourse(id: number) {
  return request<ApiResponse<Course>>(`/course/${id}`, {
    method: "DELETE",
  });
}

export function findCourses(params: PaginationParams) {
  return request<ApiResponse<Course>>(`/course`, {
    method: "GET",
    params,
  });
}

export function findCourse(id: number) {
  return request<ApiResponse<Course>>(`/course/${id}`, {
    method: "GET",
  });
}
